//index.js
//获取应用实例
const app = getApp()

Page({
  data: {
    userInfo: {},
    bususer:{},
    hasUserInfo: false,
    useropenid:null,
    canIUse: wx.canIUse('button.open-type.getUserInfo')
  },
  onLoad: function () {
    console.log(app.globalData.userInfo)
    if (app.globalData.userInfo) {
      this.setData({
        userInfo: app.globalData.userInfo,
        hasUserInfo: true
      })
    }
    if (app.globalData.bususer) {
      this.setData({
        bususer: app.globalData.bususer
      })
    }
  },
  onShow:function(){
    var that=this;
    if (app.globalData.openid) {
      that.setData({
        useropenid: app.globalData.openid
      })
    }
    app.validateopenid();
  },
  getUserInfo: function(e) {
    console.log(e)
    app.globalData.userInfo = e.detail.userInfo
    this.setData({
      userInfo: e.detail.userInfo,
      hasUserInfo: true
    })
  },

  unbindclick:function(e){
    var that=this;
    wx.request({
      url: app.globalData.serverPath + "api/authenticate/wechat/unbind",
      method:'POST',
      data: {
      },
      header: {
        'Authorization': app.globalData.token
      },
      success: function (res) {
        console.log(res);
        if(!res.data.openid){
          //解除绑定成功
          wx.showToast({
            title: '解除绑定成功'
          })
          that.setData({
            userInfo: {},
            bususer: {}
          })
          app.resetbind();
        }
      }
    });
  }
})
